package com.kuaimacode.kframework.admin.services.content;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.mybatis.mapper.index.ContentMapper;
import com.kuaimacode.kframework.mybatis.models.index.Content;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ContentService extends ServiceImpl<ContentMapper, Content> {

    /**
     * 内容管理查询
     * @return
     */
    public PageInfo<Content> findAll(int pageNum,int pageSize,Content content){
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        Optional.ofNullable(content.getType()).ifPresent(type->queryWrapper.eq("type",type));
        List<Content> contents = baseMapper.selectList(queryWrapper);
        return new PageInfo<Content>(contents);
    }

    /**
     * 更新内容信息
     * @param content
     * @return
     */
    public int updateContent(Content content){
        return baseMapper.updateById(content);

    }


}
